#!/usr/bin/perl
unshift (@INC, "/home/gslab/Subroutines");
require ("get_op_line.pl");
require ("get_reqd_percentage.pl");
require ("conclusion_for_no_loss.pl");
#This function executes the commands and calls other functions for getting the required line of output
#when the loss is 0%
sub basic_input_no_loss{
	my($r1,$h1) = @_;
	`$h1 > tst1op.txt 2>&1`;                                                 #output is stored in a file.
	$ruleexec = $?;
	$file_open_for_table = open(FILE2, "prog_exit_status_rule.txt");
	$line_exec_status_config_rule = <FILE2>;
	($exec_status_config) = $line_exec_status_config_rule =~/(\d+)/;
	print("setup value is $exec_status_config\n");
	system("./expcleartable.exp");
	$file_open_for_clear = open(FILE3, "prog_exit_status_clear.txt");
	$line_exec_status_clear_table = <FILE3>;
	($exec_status_clear) = $line_exec_status_clear_table =~/(\d+)/;
	print("clear value is $exec_status_clear\n");
	$flagclear = 0;
	system("rm prog_exit_status_rule.txt");
	system("rm prog_exit_status_clear.txt");
	$aop = open(FILE1, "tst1op.txt");           
	@complete_output = <FILE1>;                                              #complete_output has the complete output of the hping3 command.
	$reqd_op_line = 0;
	($reqd_op_line,@reqd_op_line_split) = &get_op_line(@complete_output);    #Subroutine for getting proper line from whole output.
	($percentage_with_sign,$perc_number_only) = &get_reqd_percentage(@reqd_op_line_split);   #Subroutine for getting the percentage number.
        	                                                                 #reqd_op_line has the required output line.
        	                                                                 #reqd_op_line_split has the required line split and stored in an array.
        	                                                                 #spl2 has the percentage with the sign.
        	                                                                 #percnum has only the percentage number.
	&disp_command($rule,$hping);
	print("------------Output Conclusion-----------\n");
	print $reqd_op_line;                                                     #opfullarr has the required output line.
	$success_or_fail = &conclusion_for_no_loss($perc_number_only);
	print("----------------------------------------\n");
	system("rm tst1op.txt");
	$flagconfig = 0;
	$flagrule = 0;
	$flagclear = 0;
	print("-------------Results-------------\n");
	if ($exec_status_config == 0){
		print("Rule Setup: PASS\n");
		$flagconfig = 1;
	}
	else{
		print("Rule Setup: FAIL\n");
		$flagconfig = 2;
	}
	if ($ruleexec == 0){
		print("Rule execution: PASS\n");
		$flagrule = 1;
	}
	else{
		print("Rule execution: FAIL\n");
		$flagrule = 2;
	}
	if ($exec_status_clear == 0){
		print("Rule cleardown: PASS\n");
		$flagclear = 1;
	}
	else{
		print("Rule cleardown: FAIL\n");
		$flagclear = 2;
	}
	return($flagconfig,$flagrule,$flagclear,$success_or_fail);
}
1;
